#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-06-17 23:51:19
# @Author  : shitao.tommy (hero007asd@gmail.com)
# @Link    : http://example.org
# @Version : $Id$

def url(self, uri1, uri2=None, suffix=None):
    url = 'http://%s/%s' % (self.request.host, str(uri1))
    if uri2:
        url +=  '/' + str(uri2) 
    if suffix:
        url +=  suffix
    return url

def upload_path(self, path):
    return 'http://%s/upload/%s' % (self.request.host, path)

def assets_path(self, path):
    return 'http://%s/assets/%s' % (self.request.host, path)

def is_current_path(self, param):
    if param in self.request.path:
        return True
    return False

def is_current_uri(self, param):
    if self.request.uri.startswith(param):
        return True
    return False

def cur_style(self, urlpath, style):
    if self.request.uri.startswith(urlpath):
        return style
    return ''

def cur_star(self, urlpath):
    style = '<span class="am-icon-star am-fr am-margin-right admin-icon-yellow"></span>'
    if self.request.uri.startswith(urlpath):
        return style
    return ''

from lib import libtime
def stamp_2_time(self, stamp, ftime="%Y-%m-%d %H:%M:%S"):
    '''时间戳转为格式化后的字符'''
    try:
        a = libtime.timestamp_2_datetime(int(stamp), ftime)
    except Exception, e:
        a = ''
    return a

from lib.app import libtype
def get_work_type(self, type_id):
    name = libtype.get_name(type_id)
    return name